using System;
using System.Collections.Generic;
using ebcpatterns.rx;
using NUnit.Framework;

namespace ebcpatterns.tests.rx
{
    [TestFixture]
    public class test_ToStream
    {
        [Test]
        public void Non_empty_list()
        {
            var sut = new ToStream<Uri>();
            var values = new List<Uri>();
            sut.NextValue += v => values.Add(v);

            sut.Process(new Uri[] { new Uri("http://a.com"), new Uri("http://b.com") });

            Assert.AreEqual(new[] {new Uri("http://a.com"), new Uri("http://b.com"), null}, values);

        }

        
        [Test]
        public void Empty_list()
        {
            var sut = new ToStream<Uri>();
            var values = new List<Uri>();
            sut.NextValue += v => values.Add(v);

            sut.Process(new Uri[] { });

            Assert.AreEqual(1, values.Count);
            Assert.IsNull(values[0]);
        }


        [Test]
        public void EndOfStream_is_signaled()
        {
            var sut = new ToStream<int>(int.MinValue);
            var eos = false;
            sut.NextValue += delegate { };
            sut.EndOfStream += () => eos = true;

            sut.Process(new[]{42});

            Assert.IsTrue(eos);
        }
    }
}